<?php

class app
{

    public $conn_;

    public function __construct($dblink)
    {

        $this->conn_ = $dblink;
    }

    public function get_products()
    {

        $query = $this->conn_->query("SELECT * from products");

        if (mysqli_num_rows($query) > 0) {

            while ($row = $query->fetch_assoc()) {

                $items[] = $row;
            }

            return $items;
        }
    }

    public function get_products_id($id)
    {

        $query = $this->conn_->query("SELECT * FROM products WHERE id_products = $id");

        if (mysqli_num_rows($query) > 0) {

            $item = $query->fetch_assoc();

            return $item;
        }
    }

    public function check_product_stock($id)
    {
        $query = $this->conn_->query("select * from products p
                  inner join products_keys pk on p.id_products=pk.products
                  where pk.products=$id AND pk.used is null");

        return mysqli_num_rows($query);
    }
}

?>